package suche;

/* Die Klasse MitarbeiterFernster 
 * implementiert den GUI von einem 
 * ferster,den einem Mitarbeiter benutzen kann.
 * 
 * Datei: MitarbeiterFernster.java       
 * Autor: Gregory Keussi
 * 
 * Datum: 19.12.11                 Version: 0.1 
 */

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.GridLayout;
import java.awt.ScrollPane;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.util.ArrayList;
import java.util.List;

import javax.swing.ButtonGroup;
import javax.swing.JButton;
import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JRadioButton;
import javax.swing.JScrollBar;
import javax.swing.JScrollPane;
import javax.swing.JTextArea;
import javax.swing.JTextField;

import medienverwaltung.Mediumverwalter;
import personenverwaltung.Ausleihe;
import personenverwaltung.Benutzer;
import personenverwaltung.Personenverwaltung;
import personenverwaltung.Reservierung;
import personenverwaltung.Vorgangsverwaltung;
import bibvis.FassadeBibVis;

public class MitarbeiterFernster extends JFrame
{

  private static final long serialVersionUID = 1L;
  private JPanel panel1, panel2, panel3;
  private JPanel panel4, panel6;
  private JPanel panel7, panel8, panel9;
  private JPanel uPanel, upane3;
  private JLabel label1, label2, label3;
  private JLabel label4, label5;
  public JTextField tf1, tf2, tf3, tf4;
  private JScrollBar vBar;
  JRadioButton aus, res;
  public JPanel upanel7;

  public JComboBox<String> combo1, combo2, combo3, combo4, combo5;
  private JButton okButton, Suchen;
  private ButtonGroup bg;
  public JTextArea area;
  public JScrollPane sp;
  public JCheckBox check;

  private MedienSortierung p;
  private List<Ausleihe> a;
  private List<Reservierung> r;
  private List<Benutzer> be = new ArrayList<Benutzer> ();

public void Paneladd(JScrollPane p)
{
  this.upanel7.add (p);
  }
  /*
   * Implementierung den konstruktor MitarbeiterFernster. den
   * Konstructor baut alle Teile von Gui
   */

  public MitarbeiterFernster ()
  {
    super ();
    Vorgangsverwaltung vv = new Vorgangsverwaltung ();
    vv.ausleihenLaden ();
    a = vv.gibAusleihListe ();
    r = vv.gibReservierungsListe ();

    Mediumverwalter mv = new Mediumverwalter ();
    p = new MedienSortierung (mv.gibMedienListe ());

    try
    {
      Personenverwaltung pv = new Personenverwaltung ();
      be = pv.gibBenutzerListe ();

    }
    catch (Exception e)
    {
      e.printStackTrace ();
    }
    String s[] = { "Aufsatz", "Buch", "Datentraeger", "Ebook",
        "Hoerbuch", "Zeitschrift" };

    String ss[] = { "Autor/en", "Be/sp/person", "Datentyp",
        "Erscj gleich", "Erschj Gr", "Erschj Kl", "Fachgebiet",
        "Initial", "Sachgebiet", "SchlagWort", "Speichergr",
        "Stichworte", "Thema", "Titel" };

    label1 = new JLabel ("   Allgemeine Suche ");
    label2 = new JLabel ("      Meine Kriterien ");
    label3 = new JLabel ("  Medientyps ");
    label4 = new JLabel ("   Eingabe ");
    label5 = new JLabel ("   sortieren nach ");

    panel1 = new JPanel (new GridLayout (3, 1));
    panel2 = new JPanel (new GridLayout (5, 1));
    panel3 = new JPanel (new GridLayout (1, 2));
    panel4 = new JPanel (new GridLayout (2, 1));

    panel6 = new JPanel (new GridLayout (6, 2));
    panel7 = new JPanel (new GridLayout (1, 1));
    panel8 = new JPanel (new GridLayout (2, 2));
    panel9 = new JPanel (new GridLayout (1, 2));

    uPanel = new JPanel (new GridLayout (1, 3));
    upane3 = new JPanel (new GridLayout (1, 2));

    String s3[] = { "     Aufsatz", "     Buch", "     Datentraeger",
        "     Ebook", "     Hoerbuch", "     Zeitschrift" };

    panel2.add (new JLabel ("      "));
    uPanel.add (label1, BorderLayout.CENTER);
    tf1 = new JTextField ();
    JPanel upane2 = new JPanel (new GridLayout (1, 3));
    uPanel.add (tf1, BorderLayout.CENTER);
    Suchen = new JButton ("suche");

    Suchen.addActionListener (new MySuchAktion (this, p, be));
    upane2.add (Suchen, BorderLayout.CENTER);

    upane2.add (new JLabel ("      "));
    upane2.add (new JLabel ("      "));
    uPanel.add (upane2, BorderLayout.CENTER);
    panel2.add (new JLabel ("      "));
    panel2.add (uPanel, BorderLayout.NORTH);
    panel2.add (label2);
    panel1.add (panel2, BorderLayout.NORTH);

    panel6.add (label3, BorderLayout.CENTER);
    combo1 = new JComboBox<String> (s);
    panel6.add (combo1, BorderLayout.CENTER);
    panel6.add (new JLabel ("      "), BorderLayout.CENTER);
    panel6.add (new JLabel ("      "), BorderLayout.CENTER);
    tf2 = new JTextField ();
    panel6.add (label4, BorderLayout.CENTER);
    panel6.add (tf2, BorderLayout.CENTER);

    panel6.add (new JLabel ("      "), BorderLayout.CENTER);
    panel6.add (new JLabel ("      "), BorderLayout.CENTER);

    panel6.add (label5, BorderLayout.CENTER);
    combo2 = new JComboBox<String> (ss);
    panel6.add (combo2, BorderLayout.CENTER);
    panel4.add (panel6, BorderLayout.CENTER);

    panel7.add (new JLabel ("     Ausgeliehenen und "
        + "       Reservierten Medien"), BorderLayout.CENTER);
    panel4.add (panel7, BorderLayout.CENTER);

    bg = new ButtonGroup ();
    JPanel upane8 = new JPanel (new GridLayout (1, 2));
    aus = new JRadioButton ("Ausgeliehenen");
    aus.setSelected (true);
    bg.add (aus);
    check = new JCheckBox ("Exemplare");
    upane8.add (aus, BorderLayout.CENTER);// *****
    res = new JRadioButton ("Reservierten");
    bg.add (res);

    upane8.add (res, BorderLayout.CENTER);
    panel8.add (upane8);
    panel8.add (new JLabel (" "));

    JPanel upane82 = new JPanel (new GridLayout (1, 2));
    upane82.add (check);
    upane82.add (new JLabel (" "));
    panel8.add (upane82);

    panel8.add (new JLabel (" "));
    JPanel upane4 = new JPanel (new GridLayout (7, 1));
    upane4.add (panel8, BorderLayout.CENTER);
    JPanel upane5 = new JPanel (new GridLayout (1, 2));
    upane5.add (new JLabel ("      Spezifikation"));
    tf3 = new JTextField ();
    tf3.setToolTipText ("Nur Titel eingeben");
    upane5.add (tf3);

    upane4.add (upane5);
    upane4.add (new JLabel ("       "));
    panel9.add (new JLabel ("      Sortieren nach "),
        BorderLayout.CENTER);
    combo3 = new JComboBox<String> (s3);
    panel9.add (combo3);
    upane4.add (panel9);
    upane4.add (new JLabel ("       "));
    upane4.add (new JLabel ("       "));
    JPanel upane6 = new JPanel (new GridLayout (1, 5));
    JButton standort = new JButton ("Standort");
    standort.addActionListener (new ActionListener ()
    {
      @Override
      public void actionPerformed (ActionEvent arg0)
      {
        // TODO: Variabel den gefundenen Standort eintragen

        // Testdaten:
        String name = "Marquardstrasse";
        int regalID = 1;
        int etage = 5;
        int abschnitt = 5;

        new FassadeBibVis ().zeigeStandort (name, regalID, etage,
            abschnitt);
      }
    });
    /* new suchAktionStandort ()); */
    upane6.add (standort);
    upane6.add (new JLabel ("       "));
    upane6.add (new JLabel ("       "));
    okButton = new JButton ("      OK ");
    okButton.addActionListener (new MySuchAktionOk (this, p, a, r, be));
    upane6.add (okButton);
    upane4.add (upane6);

    upane3.add (upane4);

    JPanel upane31 = new JPanel (new GridLayout (2, 1));
    JPanel upane312 = new JPanel (new GridLayout (3, 1));
    JPanel up = new JPanel (new GridLayout (1, 2));
    up.add (new JLabel ("  "));
    up.add (new JLabel ("     Suchen nach Persone "));
    upane312.add (up);
    upane312.add (new JLabel (" "));
    JPanel upane3121 = new JPanel (new GridLayout (1, 3));
    upane3121.add (new JLabel (" "));
    upane3121.add (new JLabel ("Persontyps"));

    String sb[] = { "Administrator", "Mitarbeiter", "Student" };
    combo4 = new JComboBox<String> (sb);
    upane3121.add (combo4);
    upane312.add (upane3121);
    upane31.add (upane312);

    JPanel upane321 = new JPanel (new GridLayout (4, 1));
    upane321.add (new JLabel (" "));
    JPanel upane3212 = new JPanel (new GridLayout (1, 3));
    upane3212.add (new JLabel (" "));
    upane3212.add (new JLabel ("  Eingabe "));

    tf4 = new JTextField ();
    tf4.setToolTipText ("Nur PersonalNR oder Benutzer_Nr eingeben");
    upane3212.add (tf4);
    upane321.add (upane3212);
    upane321.add (new JLabel (" "));
    JPanel upane3222 = new JPanel (new GridLayout (1, 3));
    upane3222.add (new JLabel (" "));
    upane3222.add (new JLabel ("sortieren nach"));

    String st[] = { "IBenutzer-Nr", "Nachname", "Personal-Nr" };
    combo5 = new JComboBox<String> (st);
    upane3222.add (combo5);
    upane321.add (upane3222);

    upane31.add (upane321);
    upane3.add (upane31);

    panel3.add (panel4, BorderLayout.CENTER);
    area = new JTextArea ();
    area.setEditable (false);
    sp = new JScrollPane (area);
    upanel7 = new JPanel (new BorderLayout ());
    upanel7.add (sp);
    vBar = new JScrollBar (JScrollBar.VERTICAL);

    upanel7.add (vBar, BorderLayout.EAST);
    panel3.add (upanel7, BorderLayout.CENTER);

    panel1.add (panel3);
    panel1.add (upane3, BorderLayout.CENTER);
    this.getContentPane ().add (panel1);

    Dimension bildschirm = java.awt.Toolkit.getDefaultToolkit ()
        .getScreenSize ();
    int hohe = (int) bildschirm.getHeight ();
    int breite = (int) bildschirm.getWidth ();
    this.setSize (breite, hohe);

    this.setLocation (0, 0);
    this.setVisible (true);

  }
}
